package com.zhuzhe.blog.MQlistener;

import com.zhuzhe.mq.mqtype.rabbitmq.init.MQMessageHandleService;
import com.zhuzhe.mq.mqtype.rabbitmq.sender.RabbitmqSender;
import com.zhuzhe.blog.config.MQServiceProperties;
import com.zhuzhe.blog.config.MQserviceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * MQ消息监听 消息调度中心
 *
 * @author ICE_GOD
 * @date 2020/10/12 20:49
 */
@Component
public class MQlistener extends MQMessageHandleService {
    @Autowired
    private RabbitmqSender rabbitmqSender;
    @Autowired
    private MQserviceConfig mQserviceConfig;

    @Override
    public void dealMessage(String dataType, String message) {
        System.out.println("接收到消息:" + dataType + ":" + message);
        List<MQServiceProperties> serviceList = mQserviceConfig.getServiceList();
        for (MQServiceProperties mqServiceProperties : serviceList) {
            List<String> serviceDataTypeList = mqServiceProperties.getDataTypeList();
            String serviceServerName = mqServiceProperties.getServerName();
            if (serviceDataTypeList.contains(dataType)) {
                rabbitmqSender.send(serviceServerName, dataType, message, false);
            }
        }
    }
}
